package com.dyb.recuitment.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.dyb.recuitment.entity.CompanyIndustry;
import com.dyb.recuitment.entity.JobCategory;
import com.dyb.recuitment.mapper.JobCategoryMapper;
import com.dyb.recuitment.service.IJobCategoryService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Date;
import java.util.List;

/**
 * <p>
 * 岗位分类表 服务实现类
 * </p>
 *
 * @author 邓宇斌
 * @since 2022-02-23
 */
@Service
public class JobCategoryServiceImpl extends ServiceImpl<JobCategoryMapper, JobCategory> implements IJobCategoryService {

    @Autowired
    private JobCategoryMapper jobCategoryMapper;

    DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");

    @Override
    public JobCategory getById(JobCategory jobCategory) {
        jobCategory.setStatus(1);
        QueryWrapper<JobCategory> queryWrapper = new QueryWrapper<>(jobCategory);
        List<JobCategory> result = jobCategoryMapper.selectList(queryWrapper);
        if (result.size() > 0) {
            return result.get(0);
        }
        return null;
    }

    @Override
    public int add(JobCategory jobCategory) {
        LocalDateTime localDateTime = LocalDateTime.parse(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()), df);
        jobCategory.setCreateTime(localDateTime).setUpdateTime(localDateTime);
        return jobCategoryMapper.insert(jobCategory);
    }

    @Override
    public int update(JobCategory jobCategory) {
        LocalDateTime localDateTime = LocalDateTime.parse(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()), df);
        jobCategory.setUpdateTime(localDateTime);
        return jobCategoryMapper.updateById(jobCategory);
    }

    @Override
    public int delete(JobCategory jobCategory) {
        LocalDateTime localDateTime = LocalDateTime.parse(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()), df);
        jobCategory.setStatus(0).setUpdateTime(localDateTime);
        return jobCategoryMapper.updateById(jobCategory);
    }

    @Override
    public List<JobCategory> selectByJobCategory(JobCategory jobCategory) {
        jobCategory.setStatus(1);
        QueryWrapper<JobCategory> queryWrapper = new QueryWrapper<>(jobCategory);
        return jobCategoryMapper.selectList(queryWrapper);
    }

    @Override
    public List<JobCategory> selectAllJobCategory() {
        return jobCategoryMapper.selectList(new QueryWrapper<>());
    }
}
